﻿<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

//load css
JHTML::stylesheet( 'monoslideshow.css', 'administrator/components/com_jmonoslideshow/assets/css/' );
//load jquery
JHTML::script( 'jquery-1.4.3.min.js', 'administrator/components/com_jmonoslideshow/assets/js/' );
//load plupload with flash runtime
JHTML::script("plupload.min.js", "administrator/components/com_jmonoslideshow/assets/js/pupload/");
JHTML::script("plupload.flash.min.js", "administrator/components/com_jmonoslideshow/assets/js/pupload/");
JHTML::script("jquery.plupload.queue.min.js", "administrator/components/com_jmonoslideshow/assets/js/pupload/");


$db =& JFactory::getDBO();
$nullDate 		= $db->getNullDate();
$params = &JComponentHelper::getParams( 'com_jmonoslideshow' );
jimport('joomla.environment.uri' );
$host = JURI::root();

$ajaxUpload = "
		jQuery.noConflict();
		
		jQuery(function() {
		
	var uploader = new plupload.Uploader({
		runtimes : 'flash',
		multi_selection: false,
		browse_button : 'pickfiles',
		multipart :true,
		multipart_params : {check : '".JUtility::getToken()."'},
		max_file_size : '".$params->get( 'upload_maxsize', 2 )."mb',
		chunk_size : '1mb',
		url : '".$host."administrator/index.php?option=com_jmonoslideshow&controller=upload&task=uploadAlbum',
		resize : {width : ".$params->get( 'width_vignette', 75 ).", height : ".$params->get( 'height_vignette', 65 ).", quality : ".$params->get( 'qualtiy_image', 75 )."},
		flash_swf_url : '".$host."administrator/components/com_jmonoslideshow/assets/js/pupload/plupload.flash.swf',
		filters : [
			{title : \"Image\", extensions : \"jpg,png\"}
			
		]
	});
	
	
	uploader.bind('Error', function(up, err) {
         jQuery('#filelist').append(\"<div>Error: \" + err.code +
                 \", Message: \" + err.message +
                 (err.file ? \", File: \" + err.file.name : \"\") +
                 \"</div>\"
                 );
             });
	

	uploader.bind('FilesAdded', function(up, files) {
		jQuery.each(files, function(i, file) {
			jQuery('#filelist').append(
				'<div id=\"' + file.id + '\">' +
				file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
			'</div>');
		});
	});
	
	

	uploader.bind('UploadProgress', function(up, file) {
		jQuery('#' + file.id + \" b\").html(file.percent + \"%\");
	});
	
	uploader.bind('FileUploaded', function(up, file, json) {
			var obj = eval('(' + json.response + ')');
			jQuery('#upload_etat').val('ok');
			jQuery('#upload_media_name').val (obj.fileName);
			if (obj.html == 'success')
			{
			
				jQuery('#message_upload').removeClass('alert');
				jQuery('#message_upload').removeClass('info');
				jQuery('#message_upload').addClass('approved').html(obj.msg);
			}
			else
			{
				jQuery('#message_upload').removeClass('approved');
				jQuery('#message_upload').removeClass('info');
				jQuery('#message_upload').addClass('alert').html(obj.msg);	
			}
			jQuery('#pickfiles').html(\"  ". JText::_('COM_JMONOSLIDESHOW_UPLOAD_IMAGE' )." \");
	});

	jQuery('#uploadfiles').click(function(e) {
		
		uploader.start();
		e.preventDefault();
	});

	uploader.init();
	
	jQuery('#message_upload').addClass('info').html(\"". JText::_( 'COM_JMONOSLIDESHOW_INFO_UPLOAD' )."\");
	
	uploader.bind('FilesAdded', function(up, files) {
        jQuery('#upload_etat').val('upload');
		jQuery('#message_upload').removeClass('alert');
		jQuery('#message_upload').removeClass('approved');
		jQuery('#message_upload').addClass('info').html(\"". JText::_( 'COM_JMONOSLIDESHOW_INFO_UPLOAD' )."\");
		jQuery('#pickfiles').html(\" <img src='components/com_jmonoslideshow/assets/images/ajax-loader.gif' align='absmiddle' /> ". JText::_('COM_JMONOSLIDESHOW_UPLOADING_MEDIA' )." \");
		uploader.start();
		});
});
		";
$doc = &JFactory::getDocument();									 
$doc->addScriptDeclaration($ajaxUpload);
?>

<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if (form.title.value == ""){
		alert( "<?php echo JText::_( 'COM_JMONOSLIDESHOW_YOU_MUST_ENTER_A_TITLE' );  ?>" );
	}
	
	else if (form.catid.value == "0" ){
		alert( "<?php echo JText::_( 'COM_JMONOSLIDESHOW_YOU_MUST_SELECT_A_CATEGORY' );  ?>" );
	}
	<?php if ($this->isNew) : ?>
	else if (form.upload_etat.value == ""){
		alert( "<?php echo JText::_( 'COM_JMONOSLIDESHOW_YOU_MUST_SELECT_AN_IMAGE' );  ?>" );
	}
	
	<?php endif ?>
	else if (form.upload_etat.value == "upload"){
		alert( "<?php echo JText::_( 'COM_JMONOSLIDESHOW_PLEASE_WAIT_AN_UPLOAD' );  ?>" );
	}
	else {
		submitform( pressbutton );
	}
}
</script>



<form action="index.php" method="post" name="adminForm" id="adminForm" >
<div class="col100">

<table cellspacing="0" cellpadding="0" border="0" width="100%">
		<tr>
			<td valign="top">


	<fieldset class="adminform">
		<legend><?php echo JText::_( 'COM_JMONOSLIDESHOW_DETAILS' ); ?></legend>

		<table class="admintable">
		<tr>
			<td width="100" align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_TITLE' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="title" id="title" size="32" maxlength="250" value="<?php echo $this->album->title;?>" />
			</td>
		</tr>
        
        <tr>
			<td width="100" align="right" class="key">
				<label for="description">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_DESCRIPTION' ); ?>:
				</label>
			</td>
			<td>
				<textarea name="description" cols="30" rows="10"><?php echo $this->album->description;?></textarea>
		  </td>
		</tr>
        <?php if (!$this->isNew) : ?>
          <tr>
			<td width="100" align="right" class="key">
				<label for="published">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_PUBLISHED' ); ?>
				</label>
			</td>
			<td>
				<?php echo $this->lists['published']; ?>
		  </td>
		</tr>
        
        <?php endif ?>
          
        <tr>
			<td valign="top" align="right" class="key">
				<label for="media">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_ADD_IMAGE' ); ?>:
				</label>
              
			</td>
			<td>
				
                 <div class="wrapper">

                 <div id="pickfiles" class="button"><?php echo JText::_( 'COM_JMONOSLIDESHOW_UPLOAD_IMAGE' ); ?></div>
                 </div>
                 <div id="message_upload"></div>
                 
                 
		<div>
		<div id="filelist"></div>
		
	</div>
 		<input name="upload_etat" id="upload_etat" type="hidden" value="" />
         <input name="upload_media_name" id="upload_media_name" type="hidden" value="" />
			</td>
		</tr>
        
        <?php if (!$this->isNew) : ?>
        
         <tr>
			<td valign="top" align="right" class="key">
				<label for="catid">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_IMAGE' ); ?>:
				</label>
			</td>
			<td>
				 <img src="<?php echo JURI::root(); ?>images/monoslideshow/albums/<?php echo $this->album->id; ?>.jpg" />
                
			</td>
		</tr>
        
         <?php endif ?>
        
 
       
		<tr>
			<td valign="top" align="right" class="key">
				<label for="catid">
					<?php echo JText::_( 'COM_JMONOSLIDESHOW_CATEGORY' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->lists['catid']; ?>
			</td>
		</tr>
	</table>
	</fieldset>
    </td>
    <td width="250" valign="top">
    
     <?php
			$title = JText::_( 'COM_JMONOSLIDESHOW_INFORMATION' );
			echo $this->pane->startPane( 'stat-pane' );
			echo $this->pane->startPanel( $title, 'information' );
			
			?>
            
             <table>
	 
	  <tr>
		  <td nowrap="nowrap"><label for="created"><?php echo JText::_('COM_JMONOSLIDESHOW_MEDIA_CREATED') ?> :</label></td>
		  <td width="100%">
          <?php
				if ( $this->album->created == $nullDate ) {
					echo JText::_( 'COM_JMONOSLIDESHOW_NEW_MEDIA' );
				} else {
					echo JHTML::_('date',  $this->album->created,  JText::_('DATE_FORMAT_LC2') );
				}
				?>
          
          </td>
	  </tr>
      <tr>
		<td><label for="author"><?php echo JText::_('COM_JMONOSLIDESHOW_AUTHOR') ?> : </label></td>
		<td>
		<?php
        $author =& JFactory::getUser($this->album->author);
		echo $author->name;
		

		?>
        </td>
	  </tr>
      
      
      <tr>
		  <td nowrap="nowrap"><label for="modified"><?php echo JText::_('COM_JMONOSLIDESHOW_MEDIA_MODIFIED') ?> :</label></td>
		  <td width="100%">
          <?php
				if ( $this->album->modified == $nullDate ) {
					echo JText::_( 'COM_JMONOSLIDESHOW_NEW_MEDIA' );
				} else {
					echo JHTML::_('date',  $this->album->modified,  JText::_('DATE_FORMAT_LC2') );
				}
				?>
          
          </td>
	  </tr>
      
      
       <tr>
		<td><label for="modified_by"><?php echo JText::_('COM_JMONOSLIDESHOW_MODIFIED_BY') ?> : </label></td>
		<td>
		<?php
        $modified_by =& JFactory::getUser($this->album->modified_by);
		echo $modified_by->name;
		

		?>
        </td>
	  </tr>
      </table>
            
            
            <?php
			echo $this->pane->endPanel();
			
			
			
			echo $this->pane->endPane();
			
			?>
    
    </td></tr></table>
</div>
<div class="clr"></div>

<input type="hidden" name="option" value="com_jmonoslideshow" />
<input type="hidden" name="id" value="<?php echo $this->album->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="albums" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>